package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetMealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
@Api(tags = "套餐管理")
public class SetMealController {
    @Autowired
    SetMealService setMealService;

    @ApiOperation("新增套餐")
    @PostMapping
    public Result<String> insert(@RequestBody SetmealDTO setmealDTO){
        log.info("setmealDTO:{}",setmealDTO);
        setMealService.insert(setmealDTO);
        return Result.success();
    }


    @ApiOperation("套餐分页查询")
    @GetMapping("/page")
    public Result<PageResult> selectByPage(Integer categoryId,String name,Integer page ,Integer pageSize,Integer status){
        log.info("分页查询参数:{},{},{},{},{}",categoryId,name,page,pageSize,status);
        PageResult pageResult=setMealService.selectByPage(categoryId,name,page,pageSize,status);
        return Result.success(pageResult);
    }


    @ApiOperation("修改套餐")
    @PutMapping
    public Result<String> update(@RequestBody SetmealDTO setmealDTO){
        log.info("setmealDTO:{}",setmealDTO);
        setMealService.update(setmealDTO);
        return Result.success();
    }

    @ApiOperation("根据套餐id查询套餐")
    @GetMapping("/{id}")
    public Result<SetmealVO> update(@PathVariable Long id){
        log.info("id:{}",id);
        SetmealVO setmealVO=setMealService.getById(id);
        return Result.success(setmealVO);
    }

    @ApiOperation("修改套餐的状态")
    @PostMapping("status/{status}")
    public Result<String> modifyStatus(@PathVariable Integer status,Long id){
        log.info("status:{}",status);
        setMealService.changeStatus(status,id);
        return Result.success();
    }


    @ApiOperation("批量删除套餐")
    @DeleteMapping
    public Result<String> deleteIds(@RequestParam List<Long> ids){
        log.info("ids:{}",ids);
        setMealService.deleteByIds(ids);
        return Result.success();
    }

}
